package com.qfedu.controller;

import com.alibaba.fastjson.JSON;
import com.qfedu.entity.Good;
import com.qfedu.service.GoodService;
import com.qfedu.service.impl.GoodServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

//得到全部商品信息
@WebServlet("/good/list.do")
public class GoodController extends HttpServlet {
    private GoodService service = new GoodServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        try {
            List<Good> all = service.findAll();
            String s = JSON.toJSONString(all);
            resp.getWriter().println(s);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
